package HashTable;

import java.util.HashMap;

public class _454_4SumII {
    public int fourSumCount(int[] A, int[] B, int[] C, int[] D) {
        HashMap<Integer, Integer> mp1 = new HashMap<>();
        HashMap<Integer, Integer> mp2 = new HashMap<>();
        int res = 0;
        int length = A.length;
        for (int i = 0; i < length; i++) {
            for (int j = 0; j < length; j++) {
                mp1.put(A[i] + B[j], mp1.getOrDefault(A[i] + B
                        [j], 0) + 1);
            }
        }
        for (int i = 0; i < length; i++) {
            for (int j = 0; j < length; j++) {
                res += mp1.getOrDefault(-(C[i] + D[j]), 0);
            }
        }
        return res;
    }
}
